package markan.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class TCConnection {
	
	private final static String DOTCLOUD_DB_MYSQL_HOST = "jdbc:mysql://mysql-SZQJA6TX.azva.dotcloud.net:44265/mysql";
	private final static String DOTCLOUD_DB_MYSQL_LOGIN = "root";
	private final static String DOTCLOUD_DB_MYSQL_PASSWORD = "udNXfDXLqx4Po0jnVGEx";
	
	public TCConnection() {
		try {
			Class.forName("com.mysql.jdbc.Driver").newInstance();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public Connection getConnection() throws SQLException {
		return DriverManager.getConnection(DOTCLOUD_DB_MYSQL_HOST, DOTCLOUD_DB_MYSQL_LOGIN, DOTCLOUD_DB_MYSQL_PASSWORD);
	}
	
	public static void main(String[] args) {
		try {
			// The newInstance() call is a work around for some
			// broken Java implementations

			Class.forName("com.mysql.jdbc.Driver").newInstance();
		} catch (Exception ex) {
			ex.printStackTrace();
			System.err.println("드라이버 연결 에러.");
		}
		
		Connection conn = null;
		try {
			final String DOTCLOUD_DB_MYSQL_HOST = "jdbc:mysql://teamcloud-SZQJA6TX.azva.dotcloud.net:41639";
//			final String DOTCLOUD_DB_MYSQL_LOGIN = "root";
			final String DOTCLOUD_DB_MYSQL_LOGIN = "teamcloud";
			final String DOTCLOUD_DB_MYSQL_PASSWORD = "t8NNAArFfe5rVDQ78yyO";
			
			conn = DriverManager.getConnection(DOTCLOUD_DB_MYSQL_HOST, DOTCLOUD_DB_MYSQL_LOGIN, DOTCLOUD_DB_MYSQL_PASSWORD);
			
			if(conn!=null) {
				System.out.println("연결 성공");
			}
		} catch (SQLException ex) {
			ex.printStackTrace();
			System.err.println("SQLException: " + ex.getMessage());
			System.err.println("SQLState: " + ex.getSQLState());
			System.err.println("VendorError: " + ex.getErrorCode());
		}

	}
}
